package com.iraeta.controller.page;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.iraeta.common.AuthAccess;
import com.iraeta.controller.BaseController;
import com.iraeta.service.page.BpmKaoQinServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController(value = "KaoQinController")
@RequestMapping("kaoqin")
public class KaoQinController extends BaseController {
    @Autowired
    BpmKaoQinServiceImpl bpmKaoQinService;

    @RequestMapping("kaoqingmonthdata")
    @AuthAccess
    public String KaoQinMonthData(@RequestBody JSONObject jo){
        String beginDate = jo.getString("beginDate");
        String endDate = jo.getString("endDate");
        if(StrUtil.isEmpty(beginDate)){
            return this.error("月份不能为空");
        }
        JSONArray gzrJSONArray = jo.getJSONArray("gzrList");
        List<Integer> gzrList = new ArrayList<>();
        for(int k = 0;k<gzrJSONArray.size();k++){
            gzrList.add(gzrJSONArray.getIntValue(k));
        }
        if(gzrList.size() == 0){
            return this.error("请勾选工作日");
        }
        List<HashMap<String, Object>> res = bpmKaoQinService.listKaoQin(beginDate,endDate,gzrList);
        return this.success(res);
    }
}
